/*
 *  Audio.h
 *  c_Render
 *
 *  Created by liao peterson on 3/10/10.
 *  Copyright 2010 uestc. All rights reserved.
 *
 */

//#include <AVFoundation/AVFoundation.h>
#ifndef AUDIO_H__
#define AUDIO_H__

#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#include <AudioToolbox/AudioToolbox.h>
#include <AudioToolbox/ExtendedAudioFile.h>
#include"Macros.h"

#define kDefaultDistance 25.0
typedef ALvoid	AL_APIENTRY	(*alBufferDataStaticProcPtr) (const ALint bid, ALenum format, ALvoid* data, ALsizei size, ALsizei freq);
ALvoid  alBufferDataStaticProc(const ALint bid, ALenum format, ALvoid* data, ALsizei size, ALsizei freq);

void* GetAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei*	outSampleRate);

class Audio{
public:
	void initBuffer();
	void initSource();
	void initOpenAL();
	
	void startSound();
	void teardownOpenAL();
	
	void*data;
	ALuint					source;
	ALuint					buffer;
	ALCcontext*				context;
	ALCdevice*				device;
	
	CGPoint					sourcePos;
	CGPoint					listenerPos;
	CGFloat					listenerRotation;
	ALfloat					sourceVolume;
	GLboolean				isPlaying;
	GLboolean				wasInterrupted;
};

#endif